package com.egghiro.j2se.game.sace.model.actor.option;

import com.egghiro.framework.j2se.game.core.model.actor.Actor2D;
import com.egghiro.framework.j2se.game.core.model.actor.IActor2D;
import com.egghiro.framework.j2se.game.core.view.SImage;
import com.egghiro.framework.j2se.game.utils.PropertyUtils;
import com.egghiro.j2se.game.sace.device.factory.bulletfactory.ForwardBulletFactory;
import com.egghiro.j2se.game.sace.model.actor.BulletCluster;
import com.egghiro.j2se.game.sace.model.actor.bullet.bulletshooter.BulletShooter;
import com.egghiro.j2se.game.sace.param.Direction;
import com.egghiro.j2se.game.sace.param.SACEConst;
import com.egghiro.j2se.game.sace.state.actorstate.RevolutionClockwiseState;

public class TaikyokuOption extends Option {
    private static final SImage IMG = SImage.createImage(PropertyUtils.getAIMPropertyValue(SACEConst.AIM_P_DIR,
            SACEConst.AIM_P_Key_IMG_TAIKYOKU_RED_MID));
    private static final long INTERVAL = 0;

    // private static final SImage IMG = SImage.createImage(PropertyUtils
    // .getAIMPropertyValue(SACEConst.AMI_P_Key_IMG_REIMU_SQUARE_MID));

    private BulletShooter bulletShooter;

    // TODO 这个接口是测试用。实际使用的时候还需要其他的参数
    public TaikyokuOption(Actor2D mainActor, BulletCluster canvasPlayerBulletCluster) {
        this(mainActor, canvasPlayerBulletCluster, null);
    }

    // TODO 这个接口是测试用。实际使用的时候还需要其他的参数
    public TaikyokuOption(Actor2D mainActor, BulletCluster canvasPlayerBulletCluster, IActor2D target) {
        super(IMG.getWidth() * 2, IMG.getHeight() * 2, IMG, mainActor, target);
        setState(new RevolutionClockwiseState(this, mainActor, 0, -10, 150, 0, 3));

        // TODO TEST
        bulletShooter = new BulletShooter(0, 0, canvasPlayerBulletCluster, new ForwardBulletFactory(), INTERVAL) {
            @Override
            protected void fire(int flyerX, int flyerY, IActor2D target, int axisAngle) {
                this.canvasBulletCluster.add(this.factory.createFlyer(flyerX + this.shiftX, flyerY + this.shiftY, 30,
                        axisAngle - this.shiftAngle, this.coverAngle, this.stepAngle, target, 1000));
            }
        };
    }

    @Override
    public void fire() {
        // TODO
        // bulletShooter.start();
        bulletShooter.act(this.get2DX(), this.get2DY(), null, (int) Direction.UP.getValue());
    }

}
